<?php

namespace app\admin\controller;

use think\Db;

Class Nameauth extends Base
{
    public function nameAuthList()
    {
        $obj = Db::table("tb_user_auth")->order('status', 'asc')->order('id', 'desc');
        $param = $this->request->get();
        if (isset($param['word']) && $param['word']) {
            $obj->where('id|username', $param['word']);
        }
        if (isset($param['status']) && $param['status']>-1) {
            $obj->where('status', $param['status']);
        }
        if (isset($param['start']) && $param['start']) {
            $obj->where('time', '>', strtotime($param['start']));
        }
        if (isset($param['end']) && $param['end']) {
            $obj->where('time', '<', strtotime($param['end']));
        }
        $list = $obj->paginate(10, false, ['query' => $this->request->param()]);

        return view('', ['list' => $list]);
    }

    public function nameAuthStatus()
    {
        $data = $this->request->post();
        $updateData = array();
        $updateData['status'] = $data['status'];
        $res = Db::table("tb_user_auth")->where('id', $data['id'])->update('status', $updateData);
        if ($res) {
            return ['status' => 'y', 'info' => '操作成功'];
        } else {
            return ['status' => 'n', 'info' => '操作失败'];
        }
    }

}